//#########################################################################
//        p2pSL-jserver
//
// (C) Copyright by hachreak
//       Released under GPL v2.
//       Author : Hachreak (hachreak at gmail dot com)
//       WebSite: www.secondlifelab.it
//       Date: 31/lug/07 - 20:18:49
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
//#########################################################################

/**
 *  31/lug/07 - 20:18:49
 *  Create by hachreak
 *  Under GPL V2 license
 */

package it.secondlifelab.p2pSL.jserver;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Enumeration;
import java.util.Iterator;

/**
 * @author hachreak
 *
 * class for save directory shared
 */
public class DirectorySaver {

	/**
	 * @throws IOException 
	 * 
	 */
	public DirectorySaver(Iterator<String> files) throws IOException {
		OutputStreamWriter o = new OutputStreamWriter(
				new FileOutputStream(new File(DirectoryLoader.fileConfig)));
		
		while(files.hasNext())
			o.write(files.next()+"\n");
	}
	
	/**
	 * @throws IOException 
	 * 
	 */
	public DirectorySaver(Enumeration<String> files) throws IOException {
		OutputStreamWriter o = new OutputStreamWriter(
				new FileOutputStream(new File(DirectoryLoader.fileConfig)));
		
		while(files.hasMoreElements()){
			o.write(files.nextElement()+"\n");
			//System.out.println(files.nextElement());
		}
		
		o.close();
	}

}
